package wfb.frontend.threads;

import wfb.definitions.CountryDataInterface;
import wfb.definitions.WfbDbInterface;
import wfb.definitions.threadInterfaces.FillTextFieldInterface;

import javax.swing.*;
import java.awt.*;

/**
 * @author Tobias Peitzsch
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 */
public class FillTextFieldThread implements FillTextFieldInterface {
	private String country=null;
	private WfbDbInterface wdi=null;
	private JTextField field=null;
	private int mode=-1;
	/* (non-Javadoc)
	 * @see wfb.definitions.threadInterfaces.FillTextFieldInterface#setTextField(javax.swing.JTextField)
	 */
	public void setTextField(JTextField field) {
		this.field=field;
	}
	/* (non-Javadoc)
	 * @see wfb.definitions.threadInterfaces.FillTextFieldInterface#setCountry(java.lang.String)
	 */
	public void setCountry(String country) {
		this.country=country;
	}
	/* (non-Javadoc)
	 * @see wfb.definitions.threadInterfaces.FillInterface#setMode(int)
	 */
	public void setMode(int mode) {
		this.mode=mode;
	}
	/* (non-Javadoc)
	 * @see wfb.definitions.threadInterfaces.FillInterface#setWfbDbImpl(wfb.definitions.WfbDbInterface)
	 */
	public void setWfbDbImpl(WfbDbInterface wdi) {
		this.wdi=wdi;
	}
	/* (non-Javadoc)
	 * @see java.lang.Runnable#run()
	 */
	public void run() {
		if(country==null||wdi==null||field==null||mode<0) return;
		if(mode==FillTextFieldInterface.COMMENT){
			CountryDataInterface cd=wdi.getCountryData(country);//landdaten holen
			final String text;
			if(cd==null) text=null;//null abfangen
			else text	= wdi.getCountryData(country).getComment();//Kommentar holen
			EventQueue.invokeLater(new Runnable(){
				public void run(){
					field.setText(text);
				}
			});
		}
	}
}